package com.ds.lens.data.service.dao.sql.provider;

import com.ds.lens.data.service.dao.entity.LensMetric;
import org.apache.ibatis.jdbc.SQL;

public class LensMetricSqlProvider {

    public String insertSelective(LensMetric record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("lens_metric");

        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=BIGINT}");
        }

        if (record.getIntegrationId() != null) {
            sql.VALUES("integration_id", "#{integrationId,jdbcType=BIGINT}");
        }

        if (record.getName() != null) {
            sql.VALUES("name", "#{name,jdbcType=VARCHAR}");
        }

        if (record.getUnits() != null) {
            sql.VALUES("units", "#{units,jdbcType=VARCHAR}");
        }

        if (record.getDescription() != null) {
            sql.VALUES("description", "#{description,jdbcType=VARCHAR}");
        }

        if (record.getCreatedTime() != null) {
            sql.VALUES("created_time", "#{createdTime,jdbcType=TIMESTAMP}");
        }

        if (record.getMender() != null) {
            sql.VALUES("mender", "#{mender,jdbcType=VARCHAR}");
        }

        if (record.getModifiedTime() != null) {
            sql.VALUES("modified_time", "#{modifiedTime,jdbcType=TIMESTAMP}");
        }

        return sql.toString();
    }

    public String updateByPrimaryKeySelective(LensMetric record) {
        SQL sql = new SQL();
        sql.UPDATE("lens_metric");

        if (record.getIntegrationId() != null) {
            sql.SET("integration_id = #{integrationId,jdbcType=BIGINT}");
        }

        if (record.getName() != null) {
            sql.SET("name = #{name,jdbcType=VARCHAR}");
        }

        if (record.getUnits() != null) {
            sql.SET("units = #{units,jdbcType=VARCHAR}");
        }

        if (record.getDescription() != null) {
            sql.SET("description = #{description,jdbcType=VARCHAR}");
        }

        if (record.getCreatedTime() != null) {
            sql.SET("created_time = #{createdTime,jdbcType=TIMESTAMP}");
        }

        if (record.getMender() != null) {
            sql.SET("mender = #{mender,jdbcType=VARCHAR}");
        }

        if (record.getModifiedTime() != null) {
            sql.SET("modified_time = #{modifiedTime,jdbcType=TIMESTAMP}");
        }

        sql.WHERE("id = #{id,jdbcType=BIGINT}");

        return sql.toString();
    }
}
